<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" inline :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="巡检附件ids" prop="resultFileIds">
      <el-input v-model="dataForm.resultFileIds" placeholder="巡检附件ids"></el-input>
    </el-form-item>
    <el-form-item label="巡检田块ids" prop="farmlandInfoIds">
      <el-input v-model="dataForm.farmlandInfoIds" placeholder="巡检田块ids"></el-input>
    </el-form-item>
    <el-form-item label="巡检人" prop="handler">
      <el-input v-model="dataForm.handler" placeholder="巡检人"></el-input>
    </el-form-item>
    <el-form-item label="巡检计划id" prop="inspectionPlanId">
      <el-input v-model="dataForm.inspectionPlanId" placeholder="巡检计划id"></el-input>
    </el-form-item>
    <el-form-item label="部门（基地）id" prop="deptId">
      <el-input v-model="dataForm.deptId" placeholder="部门（基地）id"></el-input>
    </el-form-item>
    <el-form-item label="巡检任务编号" prop="businessNum">
      <el-input v-model="dataForm.businessNum" placeholder="巡检任务编号"></el-input>
    </el-form-item>
    <el-form-item label="巡检任务名称" prop="taskName">
      <el-input v-model="dataForm.taskName" placeholder="巡检任务名称"></el-input>
    </el-form-item>
    <el-form-item label="巡检任务内容" prop="taskContent">
      <el-input v-model="dataForm.taskContent" placeholder="巡检任务内容"></el-input>
    </el-form-item>
    <el-form-item label="巡检开始时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="巡检开始时间"></el-input>
    </el-form-item>
    <el-form-item label="巡检完成时间" prop="finishTime">
      <el-input v-model="dataForm.finishTime" placeholder="巡检完成时间"></el-input>
    </el-form-item>
    <el-form-item label="巡检结果状态 0：一切正常 1：存在异常" prop="resultStatus">
      <el-input v-model="dataForm.resultStatus" placeholder="巡检结果状态 0：一切正常 1：存在异常"></el-input>
    </el-form-item>
    <el-form-item label="巡检结果描述" prop="resultContent">
      <el-input v-model="dataForm.resultContent" placeholder="巡检结果描述"></el-input>
    </el-form-item>
    <el-form-item label="状态： 0：待处理 1：进行中 2：已处理" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态： 0：待处理 1：进行中 2：已处理"></el-input>
    </el-form-item>
    <el-form-item label="来源类型 0：主动添加 1：计划添加" prop="sourceType">
      <el-input v-model="dataForm.sourceType" placeholder="来源类型 0：主动添加 1：计划添加"></el-input>
    </el-form-item>
 
    <el-form-item label="计划时间" prop="planTime">
      <el-input v-model="dataForm.planTime" placeholder="计划时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          resultFileIds: '',
          farmlandInfoIds: '',
          handler: '',
          inspectionPlanId: '',
          deptId: '',
          businessNum: '',
          taskName: '',
          taskContent: '',
          startTime: '',
          finishTime: '',
          resultStatus: '',
          resultContent: '',
          status: '',
          sourceType: '',
          createId: '',
          createName: '',
          createTime: '',
          updateId: '',
          updateTime: '',
          updateName: '',
          version: '',
          gcFlag: '',
          planTime: ''
        },
        dataRule: {
          resultFileIds: [
            { required: true, message: '巡检附件ids不能为空', trigger: 'blur' }
          ],
          farmlandInfoIds: [
            { required: true, message: '巡检田块ids不能为空', trigger: 'blur' }
          ],
          handler: [
            { required: true, message: '巡检人不能为空', trigger: 'blur' }
          ],
          inspectionPlanId: [
            { required: true, message: '巡检计划id不能为空', trigger: 'blur' }
          ],
          deptId: [
            { required: true, message: '部门（基地）id不能为空', trigger: 'blur' }
          ],
          businessNum: [
            { required: true, message: '巡检任务编号不能为空', trigger: 'blur' }
          ],
          taskName: [
            { required: true, message: '巡检任务名称不能为空', trigger: 'blur' }
          ],
          taskContent: [
            { required: true, message: '巡检任务内容不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '巡检开始时间不能为空', trigger: 'blur' }
          ],
          finishTime: [
            { required: true, message: '巡检完成时间不能为空', trigger: 'blur' }
          ],
          resultStatus: [
            { required: true, message: '巡检结果状态 0：一切正常 1：存在异常不能为空', trigger: 'blur' }
          ],
          resultContent: [
            { required: true, message: '巡检结果描述不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态： 0：待处理 1：进行中 2：已处理不能为空', trigger: 'blur' }
          ],
          sourceType: [
            { required: true, message: '来源类型 0：主动添加 1：计划添加不能为空', trigger: 'blur' }
          ],
          createId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          createName: [
            { required: true, message: '创建用户姓名不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          updateName: [
            { required: true, message: '修改用户姓名不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号不能为空', trigger: 'blur' }
          ],
          gcFlag: [
            { required: true, message: '删除标识 -1：删除 0：正常不能为空', trigger: 'blur' }
          ],
          planTime: [
            { required: true, message: '计划时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/buss/bussinspectiontask/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.resultFileIds = data.bussinspectiontask.resultFileIds
                this.dataForm.farmlandInfoIds = data.bussinspectiontask.farmlandInfoIds
                this.dataForm.handler = data.bussinspectiontask.handler
                this.dataForm.inspectionPlanId = data.bussinspectiontask.inspectionPlanId
                this.dataForm.deptId = data.bussinspectiontask.deptId
                this.dataForm.businessNum = data.bussinspectiontask.businessNum
                this.dataForm.taskName = data.bussinspectiontask.taskName
                this.dataForm.taskContent = data.bussinspectiontask.taskContent
                this.dataForm.startTime = data.bussinspectiontask.startTime
                this.dataForm.finishTime = data.bussinspectiontask.finishTime
                this.dataForm.resultStatus = data.bussinspectiontask.resultStatus
                this.dataForm.resultContent = data.bussinspectiontask.resultContent
                this.dataForm.status = data.bussinspectiontask.status
                this.dataForm.sourceType = data.bussinspectiontask.sourceType
                this.dataForm.createId = data.bussinspectiontask.createId
                this.dataForm.createName = data.bussinspectiontask.createName
                this.dataForm.createTime = data.bussinspectiontask.createTime
                this.dataForm.updateId = data.bussinspectiontask.updateId
                this.dataForm.updateTime = data.bussinspectiontask.updateTime
                this.dataForm.updateName = data.bussinspectiontask.updateName
                this.dataForm.version = data.bussinspectiontask.version
                this.dataForm.gcFlag = data.bussinspectiontask.gcFlag
                this.dataForm.planTime = data.bussinspectiontask.planTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/buss/bussinspectiontask/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'resultFileIds': this.dataForm.resultFileIds,
                'farmlandInfoIds': this.dataForm.farmlandInfoIds,
                'handler': this.dataForm.handler,
                'inspectionPlanId': this.dataForm.inspectionPlanId,
                'deptId': this.dataForm.deptId,
                'businessNum': this.dataForm.businessNum,
                'taskName': this.dataForm.taskName,
                'taskContent': this.dataForm.taskContent,
                'startTime': this.dataForm.startTime,
                'finishTime': this.dataForm.finishTime,
                'resultStatus': this.dataForm.resultStatus,
                'resultContent': this.dataForm.resultContent,
                'status': this.dataForm.status,
                'sourceType': this.dataForm.sourceType,
                'createId': this.dataForm.createId,
                'createName': this.dataForm.createName,
                'createTime': this.dataForm.createTime,
                'updateId': this.dataForm.updateId,
                'updateTime': this.dataForm.updateTime,
                'updateName': this.dataForm.updateName,
                'version': this.dataForm.version,
                'gcFlag': this.dataForm.gcFlag,
                'planTime': this.dataForm.planTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
